package cn.wolf.netty.protocoltcp;


import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * 自定义初始化类
 */
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {


    /**
     * 自定义初始化类
     * 说明 : 编码器和解码器要放在业务处理器之前添加,不然客户端不能正常发送消息
     * @param ch            the {@link Channel} which was registered.
     * @throws Exception 异常
     */
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        //添加解码处理器 handler
        pipeline.addLast(new MyMessageDecoder());
        //添加编码处理器 handler
        pipeline.addLast(new MyMessageEncoder());
        //添加自定义业务处理器 handler
        pipeline.addLast(new MyServerHandler());
    }
}
